<?php
class AnswerModel extends Model{
	protected $Id;
	protected $TaskId;
	protected $Desc;
	protected $Correct;

	function SetId($id){
		return $this->Id=$id;
	}
	
	function SetTaskId($taskid){
		return $this->TaskId=$taskid;
	}

	function SetDesc($desc){
		return $this->Desc=$desc;
	}
	
	function SetCorrect($correct){
		return $this->Correct=$correct;
	}
	
	function GetId(){
		return $this->Id;
	}
	
	function GetTaskId(){
		return $this->TaskId;
	}

	function GetDesc(){
		return $this->Desc;
	}
	
	function GetCorrect(){
		return $this->Correct;
	}
	
	function Validate(){
		$errors =  array();
		if((strlen($this->Desc)) == 0 ){
			//Alarm BOX!!!!!!!
			$errors[] = "Answeris empty";
		}
		return $errors;
	}
	
	function InsertAnswerToSql(){
		$error = $this->Validate();
		if(count($error) > 0 ){
			return $error;    
		}
		else{
			$stmt = $this->db->sqldb->prepare("INSERT INTO answer (task_id, description, is_correct) VALUES (:task_id, :description, :is_correct)");
			$stmt->bindParam(':task_id', $this->TaskId);
			$stmt->bindParam(':description', $this->Desc);
			$stmt->bindParam(':is_correct', $this->Correct);
			$stmt->execute();
			$arr = array();
			$arr = $stmt->errorInfo();
			return $arr;
		}
	}
	
	function SelectAnswerFromSql($id){
		$temp = $this->db->query("SELECT * FROM answer WHERE task_id= ?", array($id), $fetch = FALSE, $bindType = TRUE);
		$this->Id = $temp[0]['id'];
		$this->SheetId = $temp[0]['task_id'];
		$this->Desc = $temp[0]['description'];
		$this->Correct = $temp[0]['is_correct'];
		return $temp;
	}
	
	function SelectAllAnswerFromSql(){
		$temp = $this->db->query("SELECT * FROM answer", array($id), $fetch = FALSE, $bindType = TRUE);
		return $temp;
	}
	
	/*function UpdateTaskSheetInSql(){
		$temp = $this->db->query('UPDATE task SET name=?, date=?, expire=? WHERE id= ?', array($this->Name, $this->Date, $this->Expire, $this->Id), $fetch = FALSE, $bindType = TRUE);
	}*/
	
	
}
//áéáéá
?>